<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13-vuex加减的例子-mapState的使用</title>
</head>
<body>
    <div id="app">
        <button @click="showStore">显示仓库数据</button>
        <h1>{{num}}</h1>
        <button @click="add">加</button>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <!-- 1. 引入 vuex 依赖 -->
    <script src="./node_modules/vuex/dist/vuex.js"></script>
    <script>
       //创建仓库数据
    let store = new Vuex.Store({
        state:{
            num:888,
        },
        //改变值的操作
        mutations:{
            increment:function(state){
                state.num+=1;
            }

        }
    })
        let vm = new Vue({ 
            store,
            computed: {
                totaPrice:function(){},
                ...Vuex.mapState(["num"])
            },
            el:"#app",
             methods: {
                 showStore:function(){
                     console.log(this.$store)
                 },
                 add:function(){
                     this.$store.commit("increment")
                 }
             },
        })
    </script>
</body>
</html>